<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>支付页面</title>
    <link rel="stylesheet" href="../css/page-health-orderNotice.css"/>
    <script src="../plugins/jquery/dist/jquery.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/vue/vue.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
    <script src="../plugins/qrious/qrious.js"></script>
    <script>
        var orderNo = getUrlParam("id");
    </script>
</head>
<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<div id="app" class="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><div onclick="history.go(-1)"><</div></span>
        <span class="center">传智健康</span>
        <span class="f-right"><div>...</div></span>
    </div>
    <!-- 页面内容 -->
    <h1 style="padding-left: 30px;">请扫描下方二维码进行支付!</h1>
    <hr>
    <div class="contentBox" style="width: 100%">
        <!--<img alt="" id="qrcode" style="height: 50%;width: 50%;">-->
        <img alt="" id="qrious" style="height: 50%;width: 50%;display: block;margin:0 auto;">
    </div>
</div>
</body>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            payUrl: '',
            orderNo: ''
        },
        methods: {
            payOrder() {
                axios.get('/order/createPayOrder/' + this.orderNo).then(res => {
                    if (res.status === 200) {
                        // alert("111")
                        console.log(res)
                        this.payUrl = res.data.data;
                        // 生成二维码
                        // new QRCode(document.getElementById("qrcode"), this.payUrl)
                        new QRious({
                            element: document.getElementById('qrious'),
                            level: 'L',
                            // 注意级别越高可能会影响到识别度
                            size: 300,
                            value: this.payUrl
                        });
                        this.isPay()
                    }
                })
            },
            isPay() {
                // 开启定时任务，查询付款状态
                let num = setInterval(function () {
                    // let url = '/order/isPay/'+this.orderNo;
                    axios.get('/order/isPay/' + this.orderNo).then(res => {
                        console.log(res.data)
                        if (res.data.flag && res.data.data === '1') {
                            alert("支付成功")
                            window.location.href = "/pages/pay-success.html";
                        }
                    })
                }, 5000);
                // 同时设置一个定时任务，10分钟后，终止查询，认为付款失败
                setTimeout(function () {
                    clearInterval(num);
                    alert("支付失败")
                    window.location.href = "/pages/pay-fail.html";
                }, 600000)

            }
        },
        created() {
            // alert(orderNo);
            this.orderNo = orderNo;
            this.payOrder()
        }
    });
</script>
</html>